﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCS.DAL;
using SCS.Common.Models;
using System.Linq.Expressions;
namespace SCS.Business
{
    public class Parent2Services
    {
        IUnitOfWork _unitOfWork;
        public Parent2Services()
        {
            _unitOfWork = new UnitOfWork();
        }

        /// <summary>
        /// GetAllParent
        /// </summary>
        /// <returns>parent list</returns>
        public IEnumerable<Parent> GetAllParent()
        {
            return _unitOfWork.Parent2.GetAll();
        }

        /// <summary>
        /// GetParent
        /// </summary>
        /// <param name="userID">userID</param>
        /// <returns>parent</returns>
        public Parent GetParent(int userID)
        {
            return _unitOfWork.ParentViewTeacher.Get(m => m.userID == userID).FirstOrDefault();
        }

        /// <summary>
        /// AddParent
        /// </summary>
        /// <param name="parent">Parent</param>
        /// <returns>bool</returns>
        public bool AddParent(Parent parent)
        {
            try
            {
                int id = _unitOfWork.Parent2.GetAll().Max(t => (int?)t.parentID) ?? 0;
                parent.parentID = id + 1;
                _unitOfWork.Parent2.Add(parent);
                _unitOfWork.Commit();
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
